package com.example.mvc.controller;

import com.alibaba.nacos.api.annotation.NacosInjected;
import com.alibaba.nacos.api.config.annotation.NacosValue;
import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.api.naming.pojo.Instance;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

@RestController
public class MyController {

//    @NacosInjected
//    private NamingService namingService;
//
//    @GetMapping(value = "/get")
//    @ResponseBody
//    public List<Instance> get(@RequestParam String serviceName) throws NacosException {
//        return namingService.getAllInstances(serviceName);
//    }

    @NacosValue(value = "${useLocalCache:666}", autoRefreshed = true)
    private String useLocalCache;

    @RequestMapping(value = "/get", method = RequestMethod.GET)
    @ResponseBody
    public String get() {
        return useLocalCache;
    }

    @NacosInjected
    private NamingService namingService;

    @RequestMapping(value = "/get1", method = RequestMethod.GET)
    @ResponseBody
    public List<Instance> get1(@RequestParam String serviceName) throws NacosException {
        return namingService.getAllInstances(serviceName);
    }


    @GetMapping("/aa/{path}")
    public String aa(@PathVariable String path, String b, String c) {

        if (path.equals("ooo")) {
            return "error";
        }
        if (path.contains("a")) {
            throw new RuntimeException("ddd");
        }



        return path + "----------" + LocalDateTime.now();



    }


}
